package com.zmm.util.document.collection;

import org.springframework.lang.Nullable;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 *  Map工具类
 * @author 900045
 * @description:
 * @name MapUtil
 * @date By 2021-10-26 15:29:10
 */
public final class MapUtil {

	/**
	 *  初始化 hashMap
	 *
	 * @param <K>
	 * @param <V>
	 * @return
	 */
	public static <K, V> Map<K, V> hashMap() {
		return new HashMap<K, V>();
	}

	public static boolean isEmpty(@Nullable Collection<?> collection) {
		return (collection == null || collection.isEmpty());
	}

	public static boolean isEmpty(@Nullable Map<?, ?> map) {
		return (map == null || map.isEmpty());
	}


	/**
	 * 对象转map
	 * @param obj
	 * @return
	 */
	public static Map<String, Object> objToMap(Object obj){

		Map<String, Object> map = new HashMap<>();
		// 获取f对象对应类中的所有属性域
		Class<?> clazz = obj.getClass();
		for (Field field : clazz.getDeclaredFields()) {
			field.setAccessible(true);
			
		}
		return map;
	}
}
